package com.huatai.vba.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import com.huatai.vba.execute.utils.DBFConvertDBService;
import com.huatai.vba.service.FileSaveService;
import com.huatai.vba.service.VbaFileActionService;
import com.huatai.vba.vo.TableListVo;

@RestController
@RequestMapping(value = "")
public class DemoController {

	private static final Logger logger = LoggerFactory.getLogger(DemoController.class);

	@Autowired
	private FileSaveService fileSaveService;

	@Autowired
	private VbaFileActionService vbaFileActionService;

	@Autowired
	private DBFConvertDBService dBFConvertDBService;

	@RequestMapping(value = "", method = RequestMethod.GET)
	public ModelAndView indexOfAll() {
		ModelAndView mv = new ModelAndView("compare");
		return mv;
	}

	@RequestMapping(value = "/example", method = RequestMethod.GET)
	public ModelAndView example() {
		ModelAndView mv = new ModelAndView("example");
		return mv;
	}

	@RequestMapping(value = "index", method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("index");
		// factory.execute(num);
		mv = new ModelAndView("index");
		return mv;
	}

	@RequestMapping(value = "login", method = RequestMethod.GET)
	public ModelAndView login() {
		ModelAndView mv = new ModelAndView("login");
		logger.info("index調用");
		return mv;
	}

	@RequestMapping(value = "data", method = RequestMethod.GET)
	@ResponseBody
	public List<TableListVo> getData() {
		List<TableListVo> list = new ArrayList<TableListVo>();
		list.add(new TableListVo(1, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(2, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(3, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(4, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(5, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(6, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(7, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(8, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(9, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		list.add(new TableListVo(10, "文件保存", "将文件迁移到另一个地方", "<a href=\"index.html\" class=\"btn btn-primary\">执行</a>"));
		return list;
	}

	@RequestMapping(value = "saveFile", method = RequestMethod.GET)
	public ModelAndView saveFile(String currectDate) {
		ModelAndView mv = new ModelAndView("success");
		try {
			fileSaveService.saveFile(new SimpleDateFormat("yyyyMMdd").format(new Date()));
		} catch (Exception ex) {
			mv = new ModelAndView("fail");
			logger.error("調用失敗", ex);
		}
		return mv;
	}

}
